//@ts-ignore
import { requestHttp } from "@/utils/requestHttp.ts";

//引入类型约束
import { responseCommodityInfoListData, responseCommodityCategoryListData } from "./type.ts";
import type { productInfo } from "./type.ts";

/**
 * 查询商品信息(支持分页查询) get请求
 * page=1
 * pageSize=3
 */
export const reqCommodityList = (page:number = 1, pageSize:number = 3) => {
    return requestHttp<responseCommodityInfoListData>({
        url:"/manage/commodity",
        method:"get",
        params:{
            page:page,
            pageSize:pageSize
        }
    })
}

/**
 * 查询所有的商品分类信息
 * gte 无参数要求
 */
export const reqAllCommodityCategoryList = () => {
    return requestHttp<responseCommodityCategoryListData>({
        url:"/manage/category/all",
        method:"get"
    })
}

/**
 * 更新一条商品信息
 * put 请求体 = {commodityId,commodityName,commodityDescription,commodityDiscont,commoditySales,commoditySaleMoney,commodityCategoryId,commodityImgs}
 */
export const reqUpdateCommodity = (commodityInfo:productInfo) => {
    return requestHttp({
        url:"/manage/commodity",
        method:"put",
        data:commodityInfo
    })
}

/**
 * 添加一条商品信息
 * post 请求体 = {commodityName,commodityDescription,commodityDiscont,commodityCategoryId,commodityImgs}
 */
 export const reqSaveCommodity = (commodityInfo:productInfo) => {
    return requestHttp({
        url:"/manage/commodity",
        method:"post",
        data:commodityInfo
    })
}

/**
 * 删除一条商品信息
 * delete commodityId = ?
 */
 export const reqDeleteCommodity = (commodityId:number) => {
    return requestHttp({
        url:"/manage/commodity",
        method:"delete",
        params:{
            commodityId:commodityId
        }
    })
}

/**
 * 根据商品分类对商品进行筛选接口
 * get commodityCategoryId = ?
 */
export const reqCommodityListByCategory = (commodityCategoryId:number) => {
    return requestHttp<responseCommodityInfoListData>({
        url:"/manage/commodity/category",
        method:"get",
        params:{
            commodityCategoryId
        }
    })
}

/**
 * 批量删除商品数据接口api
 * delete  commodityIds = commodityId[]
 */
export const reqDeleteCommodityBatch = (commodityIds:number[]) => {
    return requestHttp({
        url:"/manage/commodity/batch",
        method:"delete",
        data:commodityIds
    })
}

/**
 * 根据商品名称对商品进行模糊搜索api
 * get  commodityName = ?
 */
export const reqCommodityListByCommodityNmae = (commodityName:string) => {
    return requestHttp<responseCommodityInfoListData>({
        url:"/manage/commodity/like",
        method:"get",
        params:{
            commodityName:commodityName
        }
    })
}

/**
 * 对商品表进行排序输出api  前端传入排序字段commodity_sales commodity_sale_money   排序方式 asc desc
 * get  fieldName = ?  sortRule = ?
 */
export const reqCommodityListSort = (fieldName:string, sortRule:string) => {
    return requestHttp<responseCommodityInfoListData>({
        url:"/manage/commodity/sort",
        method:"get",
        params:{
            fieldName:fieldName,
            sortRule:sortRule
        }
    })
}